package main;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 *
 */
import javax.wireless.messaging.*;
import javax.microedition.io.Connector;


public class SendMessage implements Runnable{
    MessageConnection conn = null;
    TextMessage txtmessage = null;
    String shortCode = "";
    String fullSMS = "";    
    
    public SendMessage(String textMessage, String masterSMS){
        sendSms(textMessage, masterSMS);
    }

    public void sendSms( String shortCode,String fullSMS) {
        this.shortCode = shortCode;
        this.fullSMS = fullSMS;
        //System.out.println("fullSMS: " + this.fullSMS);
        new Thread(this).start();
    }

    public void run() {
        try {
            conn = (MessageConnection) Connector.open("sms://" + shortCode);
            txtmessage = (TextMessage) conn.newMessage(
                    MessageConnection.TEXT_MESSAGE);
            txtmessage.setPayloadText(fullSMS);
            conn.send(txtmessage);
        } catch (Exception ex) {
         // midlet.getDisplay().setCurrent(midlet.listDetailRelax);
        } finally {
            try {

                conn.close();
               // midlet.getDisplay().setCurrent(midlet);
            } catch (Exception ex) {
                // midlet.getDisplay().setCurrent(midlet);
            }
        }
    }
}
